﻿#encoding=utf-8
#http://code.google.com/p/haicoder/
rep = (	("Hoi", "Hoi"), )

import os

def Pause():
    os.system("@Pause")

def fPath(fpth):
    fpth = os.path.abspath(fpth)
    return fpth.upper().split("\\")

def Rx(path):
    ldir = os.listdir(path)
    for dir in ldir:
        if dir == ".svn": continue

        current = path + "\\" + dir
        if os.path.isdir(current):
            Rx(current)
        if os.path.isfile(current):

            if os.path.getsize(current) >= 1 * 1024 * 1024: # 1MB
                continue
            if fPath(__file__) == fPath(current):
                continue
            print current
            
            f = file(current, "rb")
            page = f.read()
            f.close()

            f = file(current, "wb")
            for (x, y) in rep:
                page = page.replace(x, y)
            f.write(page)
            f.close()

            backup = page
            page = page.upper()
            for (x, y) in rep:
                fdk = page.find(x.upper())
                if fdk != -1:
                    print "*" * 25
                    print backup[fdk : fdk + len(x)], current
                    Pause()
                    break

if __name__ == "__main__":
    Rx("..")
    print "*" * 79
    print "ok"
    Pause()
